const binaryRequest = (file) => {
     // code to send binary data
     let reader = new FileReader();
     reader.readAsArrayBuffer(file);
     return new Promise((resolve,reject)=> { 
        reader.onload = function(e) {
            let result = reader.result
            resolve(result)
        }
        reader.onerror = function(error) {
            reject(error)
        }
     })
     
}

const base64Request = (file) => {
    let reader = new FileReader();
    reader.readAsArrayBuffer(file);
    return new Promise((resolve,reject)=> { 
       reader.onload = function(e) {
           let result = e.target.result
           let arraybuffer = new Uint8Array(result)
           let binary =  arraybuffer.reduce((data,byte)=>data+= String.fromCharCode(byte),'')
           let base64Data = btoa(binary)
           resolve(base64Data)
       }
       reader.onerror = function(error) {
           reject(error)
       }
    })
}

const formDataRequest = () => {}



export const myRequest = {
    binaryRequest,
    base64Request,
    formDataRequest
}


